/// <reference path="../typings/index.d.ts" />
/// <reference path="../src/linePriceService.ts" />
/// <reference path="../src/tms.ts" />

describe('getLinePriceList',() => {
    var injector:ng.auto.IInjectorService;
    var service:ILinePriceService;

    beforeEach(() => {
        injector = angular.injector(['ng','tms']);
        service = injector.get<ILinePriceService>('linePriceService');
    });

    //常规无条件获取
    it('get linePrice list normal',(done) => {
        service.getList(null, null, null, null,null,null,null,null,null,null,null,null,null, 0, 10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe("|||||||||||||0|10");
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //获取企业公司编号包含4的线路报价列表
    it('get linePrice list by enterpriseid \'4\'',(done) => {
        service.getList('4',null,null,null,null, null, null, null,null,null,null,null,null,0,10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe("4|||||||||||||0|10");
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //获取货物类别编号包含 货车 的线路报价列表
    it('get linePrice list by goodtypeid \'货车\'',(done) => {
        service.getList(null,'货车',null,null,null, null, null, null,null,null,null,null,null,0,10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe("|货车||||||||||||0|10");
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //获取价格状态包含 有效 的线路报价列表
    it('get linePrice list by pricestate \'有效\' ',(done) => {
        service.getList(null,null,'有效',null,null, null, null, null,null,null,null,null,null,0,10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe("||有效|||||||||||0|10");
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //获取起始地省包含 天津 的线路报价列表
    it('get linePrice list by beginprovince \'天津\' ',(done) =>{
        service.getList(null,null,null,'天津',null,null,null, null,null,null,null,null,null,0,10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe("|||天津||||||||||0|10");
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //获取起始地市包含 天津 的线路报价列表
    it('get linePrice list by begincity \'天津\' ',(done) =>{
        service.getList(null,null,null,null,'天津',null,null, null,null,null,null,null,null,0,10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe("||||天津|||||||||0|10");
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //获取起始地区包含 和平区 的线路报价列表
    it('get linePrice list by beginarea \'和平区\'',(done) =>{
        service.getList(null,null,null,null,null,'和平区',null, null,null,null,null,null,null,0,10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe("|||||和平区||||||||0|10");
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //获取目的地省包含 河北 的线路报价列表
    it('get linePrice list by endprovince \'河北\'',(done) =>{
        service.getList(null,null,null,null,null,null,'河北', null,null,null,null,null,null,0,10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe("||||||河北|||||||0|10");
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //获取目的地市包含 唐山 的线路报价列表
    it('get linePrice list by endcity \'唐山\'',(done) =>{
        service.getList(null,null,null,null,null,null, null,'唐山',null,null,null,null,null,0,10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe("|||||||唐山||||||0|10");
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //获取目的地区包含路北区 的线路报价列表
    it('get linePrice list by endarea \'路北区\'',(done) =>{
        service.getList(null,null,null,null,null,null, null,null,'路北区',null,null,null,null,0,10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe("||||||||路北区|||||0|10");
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //获取吨位范围包含 25 的线路报价列表
    it('get linePrice list by Tonrange \'25\'',(done) =>{
        service.getList(null,null,null,null,null,null, null,null,null,'25',null,null,null,0,10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe("|||||||||25||||0|10");
            done();
        },(err) => {
            done.fail(err);
        });
    });
    
    //获取 货物编号包含5 的线路报价列表
    it('get linePrice list by GoodsId \'5\'',(done) =>{
        service.getList(null,null,null,null,null,null, null,null,null,null,'5',null,null,0,10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe("||||||||||5|||0|10");
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //获取 起始地包含江苏镇江京口区 的线路报价列表
    it('get linePrice list by beginAddress \'江苏镇江京口区\'',(done) =>{
        service.getList(null,null,null,null,null,null, null,null,null,null,null,'江苏镇江京口区',null,0,10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe("|||||||||||江苏镇江京口区||0|10");
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //获取 目的地包含湖北恩施自治州恩施市 的线路报价列表
    it('get linePrice list by endAddress \'湖北恩施自治州恩施市\'',(done) =>{
        service.getList(null,null,null,null,null,null, null,null,null,null,null,null,'湖北恩施自治州恩施市',0,10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe("||||||||||||湖北恩施自治州恩施市|0|10");
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //获取线路报价列表
    it('get linePrice list by enterpriseid \'4\' and goodtypeid \'2\' and pricestate \'有效\' and beginprovince \'江苏\' and begincity \'镇江\' and beginarea \'京口区\' and endprovince \'湖北\' and endcity \'恩施自治州\'  and endarea \'恩施市\' and Tonrange \'2\' and GoodsId \'2\' and beginAddress \'江苏镇江京口区\' and endAddres \'湖北恩施自治州恩施市\'',(done) =>{
        service.getList('4','2','有效','江苏','镇江','京口区', '湖北','恩施自治州','恩施市','2','2','江苏镇江京口区','湖北恩施自治州恩施市',0,10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe("4|2|有效|江苏|镇江|京口区|湖北|恩施自治州|恩施市|2|2|江苏镇江京口区|湖北恩施自治州恩施市|0|10");
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //获取线路报价详情
    it('get detail ',(done)=>{
        service.getDetail('2').then((res)=>{
            expect(res.data.enterpriseCompanyId).toBe("1");
            expect(res.data.openTime).toBe("2016/9/5 9:00");
            expect(res.data.goodsId).toBe("2");
            expect(res.data.closeTime).toBe("2016/9/6 15:00");
            expect(res.data.startProvince).toBe("江苏");
            expect(res.data.startCity).toBe("镇江");
            expect(res.data.startArea).toBe("京口");
            expect(res.data.endProvince).toBe("湖北");
            expect(res.data.endCity).toBe("恩施自治州");
            expect(res.data.endArea).toBe("恩施");
            expect(res.data.tonnageRange).toBe("1");
            expect(res.data.price).toBe(1100);
            expect(res.data.priceUnit).toBe("元/车");
            expect(res.data.goodsTypeId).toBe("友谊花");
            expect(res.data.loodingType).toBe("零担");
            expect(res.data.carLength).toBe("5.8米");
            expect(res.data.setleWay).toBe("公里数结算");
            expect(res.data.priceType).toBe("含税");
            expect(res.data.mileage).toBe(10);
            expect(res.data.priceState).toBe("有效");
            expect(res.data.settleName).toBe("测试收货单位");
            expect(res.data.settleContact).toBe("测试人");
            expect(res.data.settlePhone).toBe("18362868333");
            expect(res.data.remarks).toBe("测试线路报价");
            expect(res.data.extData).toBe("2");
            done();
        },(err)=>{
            done.fail(err);
        });
    });

    //添加线路报价
    it('add linePrice',(done) => {
        service.add("1","2016/9/5","1","2016/9/6","江苏","镇江","京口区","江苏","南京","江宁区","2",2000,"元/吨","亲情花","零担","4.5米","到付结算","含税",5,"有效","测试收货单位","测试收货人2","18362868111","测试备注").then((res) => {
            expect(res.data.extData).toBe("1|2016/9/5|1|2016/9/6|江苏|镇江|京口区|江苏|南京|江宁区|2|2000|元/吨|亲情花|零担|4.5米|到付结算|含税|5|有效|测试收货单位|测试收货人2|18362868111|测试备注");
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //编辑线路报价
     it("edit linePrice",(done) => {
        service.edit("1","2","2016/9/5","2","2016/9/6","江苏","镇江","京口区","江苏","南京","江宁区","2",1500,"元/吨","亲情花","零担","4.5米","到付结算","含税",7,"有效","测试收货单位2","测试收货人3","18362868666","测试备注2").then((res) => {
            expect(res.data.extData).toBe("1|2|2016/9/5|2|2016/9/6|江苏|镇江|京口区|江苏|南京|江宁区|2|1500|元/吨|亲情花|零担|4.5米|到付结算|含税|7|有效|测试收货单位2|测试收货人3|18362868666|测试备注2");
            done();
        },(err) => {
            done.fail(err);
        });
    });

});